#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define LL long long
const int INF = 1000000002;
using namespace std;

pair <int, int> all[100010];
pair <int, int> paired[100010];
int xs[100010];
int ys[100010];
int cnt[100010];
int st[100010];
int m, k;
int sz;
int n;

bool Load()
{
	scanf("%d", &n);
	if (n == 0) return 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &all[i].second, &all[i].first);
	}
	return 1;
}
inline bool cmp(const pair <int, int> &a, const pair <int, int> &b)
{
	return a.second < b.second || a.second == b.second && a.first < b.first;
}

inline bool cmp2(int a, int b)
{
	return all[a] < all[b];
}

inline int findX(int key)
{
	int l = 0;
	int r = k - 1;
	int mid;
	while (l <= r)
	{
		mid = (l + r) / 2;
		if (xs[mid] == key)
			return mid;
		else if (xs[mid] < key)
			l = mid + 1;
		else r = mid - 1;
	}
	return -1;
}

inline int findY(int key)
{
	int l = 0;
	int r =m - 1;
	int mid;
	while (l <= r)
	{
		mid = (l + r) / 2;
		if (ys[mid] == key)
			return mid;
		else if (ys[mid] < key)
			l = mid + 1;
		else r = mid - 1;
	}
	return -1;
}

void Solve()
{
	sort(all, all + n, cmp);
	int i;
/*	int l = 1;
	for (i = 1; i < n; i++)
	{
		if (all[i] != all[l - 1])
			all[l++] = all[i];
	}
	n = l;
*/

	m = 1;
	ys[0] = all[0].second;
	paired[0].first = all[0].first;
	paired[0].second = -1;
	for (i = 1; i < n; i++)
	{
		if (all[i].second != ys[m - 1])
		{
			ys[m++] = all[i].second;
			paired[m - 1].first = all[i].first;
			paired[m - 1].second = -1;
		}
		else
		{
			paired[m - 1].second = all[i].first;
		//	cerr << "paired " << paired[m - 1].first << " " << paired[m - 1].second << "\n";
		}
	}       
	sort(all, all + n);
	k = 1;
	xs[0] = all[0].first;
	for (i = 1; i < n; i++)
	{
		if (all[i].first != xs[k - 1])
			xs[k++] = all[i].first;
	}
	LL res = 0;
	int j, t;
	for (i = 0; i < n; i++)
	{
		if (i > 0 && all[i].first != all[i - 1].first)
		{
			for (j = 0; j < sz; j++)
				cnt[st[j]] = 0;
			sz = 0;
		}	
		int y = findY(all[i].second);

		if (paired[y].second != -1 && paired[y].first == all[i].first)
		{
			t = findX(paired[y].second);
			if (paired[y].second == paired[y].first) paired[y].second = -1;
			if (cnt[t] == 0)
				st[sz++] = t;
			res += (LL)cnt[t];
			cnt[t]++;
		}
	}
	for (i = 0; i < sz; i++) cnt[st[i]] = 0;
	sz = 0;
	cout << res << "\n";
}

#define file "rectcnt"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file"2.out", "wt", stdout);
	#endif
	while (Load())
	Solve();
	return 0;
}
